<?php
/*
Description: This file is used to change login paassword.
*/
#########IncludeFiles####################################################################################
include_once '../inc/config.php';
include_once("../inc/bootstrape.php");
require_once _SITE_PATH_.'classes/Vendor/Vendor.php';
require_once _SITE_PATH_.'classes/VendorsMaster/VendorsMaster.php';

require_once _SITE_PATH_.'classes/Venue/Venue.php';
require_once _SITE_PATH_.'classes/CommonUtility/CommonUtility.php';

$errMsg = $_GET['err'];
$action = trim($_REQUEST['action']);
$id = trim($_REQUEST['id']); 
if(empty($id)){
    header("Location: "._SITE_ADMIN_URL_."venue/venuetariff_mng.php");
    exit;
}

$res = Venue::getVenueTariff($id);
$result = $res[0];

$venues = Venue::getActiveVenues();

if(isset($_POST['submit'])){
    $parms['name'] = $_POST['name'];
    $parms['fixed_cost_items'] = @implode(',',$_POST['fixed_cost_items']);
    $parms['variable_cost_items'] = @implode(',',$_POST['variable_cost_items']);
    
    $parms['from_date'] = $_POST['from_date'];
    $parms['to_date'] = $_POST['to_date'];
    $parms['total_cost'] = $_POST['total_cost'];
    $parms['no_of_people'] = $_POST['no_of_people'];
    $parms['per_person_cost'] = $_POST['per_person_cost'];
    //$parms['cost_type'] = $_POST['cost_type'];
    //$parms['total_cost'] = $_POST['total_cost'];
    $parms['discount'] = $_POST['discount'];
    $parms['discount_type'] = $_POST['discount_type'];
    $parms['surcharge'] = $_POST['surcharge'];
    $parms['surcharge_type'] = $_POST['surcharge_type'];
    $parms['tax_rate'] = $_POST['tax_rate'];
    $parms['booking_amount'] = $_POST['booking_amount'];
    $parms['cancellation_policy'] = $_POST['cancellation_policy'];
    $parms['tc_policy'] = $_POST['tc_policy'];
    $parms['added'] = date("Y-m-d");
    
    $condition = array(); 
    $condition['id'] = $id;
    
    if( CommonUtility::updateData($parms, 'venue_tariff', $condition)) {   
        header("Location: venuetariff_mng.php?msg=1776");            
        exit;
    }
    $errMsg = 1777;    
}

$editor = CommonUtility::includeEditor();

$fixed_cost_items = CommonUtility::getVendorServicesByVendorId($result['vendor_id'], @explode(',',$result['fixed_cost_items']));
$variable_cost_items = CommonUtility::getAllVendorServices(null, @explode(',',$result['variable_cost_items']));

/*$fixed_cost_items = '';
if(!empty($result['fixed_cost_items'])){
    $vendor_services =VendorsMaster::getVendorService($result['fixed_cost_items']);
    $vendor_services_name = array();
    foreach($vendor_services as $key => $val){
        array_push($vendor_services_name, $val['name']);
    }
    $fixed_cost_items = implode(',',$vendor_services_name);
}

$variable_cost_items = '';
if(!empty($result['variable_cost_items'])){
    $vendor_services =VendorsMaster::getVendorService($result['variable_cost_items']);
    $vendor_services_name = array();
    foreach($vendor_services as $key => $val){
        array_push($vendor_services_name, $val['name'].' - '.$val['vendor_name']);
    }
    $variable_cost_items = implode(', ',$vendor_services_name);
}*/

if( $errMsg ){
    $result = $_POST;    
}

$_tplName = 'venue/venuetariff_edit.tpl';
$_title = 'Edit Venue Tariff';

//  calender js include
$_extraJS[] = _SITE_URL_ . 'lib/calender/js/cal.js';
require_once _ADMIN_TPL_MAIN_;
?>